<!--  -->
<template>
  <a-modal
    :maskClosable="false"
    :destroyOnClose="true"
    title="新建标签"
    centered
    :footer="null"
    :width="600"
    v-model="visible"
  >
    <div class="disFlxAC flexCenter _p-40">
      <span class="fz-16 fw-6">新标签</span>
      <a-input-search
        v-model.trim="value"
        class="width-40 _ml-10"
        placeholder="输入标签"
        size="large"
        @search="handleAdd"
      >
        <a-button type="primary" slot="enterButton"> 添加 </a-button>
      </a-input-search>
    </div>
  </a-modal>
</template>

<script>
import { labelAdd } from '@/api/activity/activity'
export default {
  props: {
    // 活动ID
    activityId: {
      type: Number | String,
    },
  },
  components: {},
  data() {
    return {
      value: '',
      visible: false,
    }
  },
  computed: {},
  watch: {},
  methods: {
    show() {
      this.value = ''
      this.visible = true
    },
    async handleAdd() {
      let reg = /^[\u4E00-\u9FA5A-Za-z0-9\s]{1,8}$/
      if (!reg.test(this.value)) return this.$message.error('标签名称长度为1-8的字符串,且不能包含特殊字符')
      let { code, data } = await labelAdd({ activityId: this.activityId, name: this.value })
      if (code === 0) {
        this.visible = false
        this.$message.success('新增成功')
        this.$emit('success', data)
      }
    },
  },
  created() {},
  mounted() {},
}
</script>
<style scoped>
</style>